package com.dqyt.khjc.controller;

import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.UserService;
import com.dqyt.khjc.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 作业信息管理
 */
@RestController
public class WorkController {

    @Autowired
    private WorkService workService;

    /**
     * 快速分配任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/setAssignTasks")
    public ResultMsg setAssignTasks(HttpServletRequest request,int type, long userId,String startNumber,String endNumber) {
        ResultMsg resultMsg = workService.setAssignTasks(request,type,userId,startNumber,endNumber);
        return resultMsg;
    }


    /**
     * 分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getWorkListPage")
    public ResultMsg getWorkListPage(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "rwdbh", required = false, defaultValue = "-1")  String rwdbh,
                                     @RequestParam(defaultValue = "-1") Integer wtfId,
                                     @RequestParam(defaultValue = "0")Integer mtype,
                                     @RequestParam(defaultValue = "0")Integer workTYpe,
                                     @RequestParam(defaultValue = "0")Integer workTYpeCh,
                                     @RequestParam(defaultValue = "0")Integer workTYpeCh2,
                                     @RequestParam(defaultValue = "0")Integer jyyId
                                     ) {
        ResultMsg resultMsg = workService.getWorkListPage(request,page,size,rwdbh,wtfId,mtype,workTYpe,workTYpeCh,workTYpeCh2,jyyId);
        return resultMsg;
    }


    /**
     * 分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getWorkListPagex")
    public ResultMsg getWorkListPagex(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "rwdbh", required = false, defaultValue = "-1")  String rwdbh,
                                     @RequestParam(defaultValue = "-1") Integer wtfId,
                                     @RequestParam(defaultValue = "0")Integer mtype,
                                     @RequestParam(defaultValue = "0")Integer workTYpe,
                                     @RequestParam(defaultValue = "0")Integer workTYpeCh,
                                     @RequestParam(defaultValue = "0")Integer workTYpeCh2,
                                     @RequestParam(defaultValue = "0")Integer jyyId
    ) {
        ResultMsg resultMsg = workService.getWorkListPagex(request,page,size,rwdbh,wtfId,mtype,workTYpe,workTYpeCh,workTYpeCh2,jyyId);
        return resultMsg;
    }


    /**
     * 分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/updateWorkById")
    public ResultMsg updateWorkById(HttpServletRequest request,long workId,long userId,String bsbh) {
        ResultMsg resultMsg = workService.updateWorkById(request,workId,userId,bsbh);
        return resultMsg;
    }


    /**
     * 删任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/deleteWorkById")
    public ResultMsg deleteWorkById(HttpServletRequest request,long workId) {
        ResultMsg resultMsg = workService.deleteWorkById(request,workId);
        return resultMsg;
    }


    /**
     * 分配任务
     * @param request
     * @param bsbhArrar  标识编号的数组
     * @param jcrUserId  检验员id
     * @param jcrStr   检验员名字
     * @return
     */
    @RequestMapping("/api/assignJobs")
    public  ResultMsg assignJobs(HttpServletRequest request,String [] bsbhArrar,String jcrUserId,String jcrStr){
        ResultMsg resultMsg = workService.assignJobs(request,bsbhArrar,jcrUserId,jcrStr);
        return resultMsg;
    }



    /**
     * 设置任务状态 已打印
     * @param request
     * @param bsbhArrar  标识编号的数组
     * @return
     */
    @RequestMapping("/api/setworkTYpeYdy")
    public  ResultMsg setworkTYpeYdy(HttpServletRequest request,String [] bsbhArrar,int workTYpe){
        ResultMsg resultMsg = workService.setworkTYpeYdy(request,bsbhArrar,workTYpe);
        return resultMsg;
    }

    /**
     * 设置任务状态 已完成
     * @param request
     * @param bsbhArrar  标识编号的数组
     * @return
     */
    @RequestMapping("/api/setworkTYpeYwc")
    public  ResultMsg setworkTYpeYwc(HttpServletRequest request,String [] bsbhArrar){
        ResultMsg resultMsg = workService.setworkTYpeYwc(request,bsbhArrar);
        return resultMsg;
    }

    /**
     * 设置任务状态 已装箱
     * @param request
     * @param bsbhArrar  标识编号的数组
     * @return
     */
    @RequestMapping("/api/setworkTYpeYzx")
    public  ResultMsg setworkTYpeYzx(HttpServletRequest request,String [] bsbhArrar){
        ResultMsg resultMsg = workService.setworkTYpeYzx(request,bsbhArrar);
        return resultMsg;
    }




    /**
     * 设置任务状态 已发放
     * @param request
     * @param bsbhArrar  标识编号的数组
     * @return
     */
    @RequestMapping("/api/setworkTYpeYff")
    public  ResultMsg setworkTYpeYff(HttpServletRequest request,String [] bsbhArrar){
        ResultMsg resultMsg = workService.setworkTYpeYff(request,bsbhArrar);
        return resultMsg;
    }


    /**
     * 工作量确认单
     * 根据任务单号  查询统计 已完成的 气瓶面罩 ，已维修的气瓶，面罩，充气 等等
     * @param request
     * @param rwdbh  任务单编号
     * @return
     */
    @RequestMapping("/api/getGzlqrdByRwdbh")
    public  ResultMsg getGzlqrdByRwdbh(HttpServletRequest request,String rwdbh){
        ResultMsg resultMsg = workService.getGzlqrdByRwdbh(request,rwdbh);
        return resultMsg;
    }




    /**
     * 工作量统计单
     * 根据任务单号  查询统计 已完成的 气瓶面罩 ，已维修的气瓶，面罩，充气 等等
     * @param request
     * @param rwdbh  任务单编号
     * @return
     */
    @RequestMapping("/api/getGzltjdByRwdbh")
    public  ResultMsg getGzltjdByRwdbh(HttpServletRequest request,String rwdbh,String sTime,String eTime,
                                       String wtfId,String jyyId,
                                       @RequestParam(defaultValue = "-1") Long wtfchId
    ){
        ResultMsg resultMsg = workService.getGzltjdByRwdbh(request,rwdbh,sTime,eTime,wtfId,wtfchId,jyyId);
        return resultMsg;
    }




    /**
     * 工作量 统计的分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getWorkStatisticsPage")
    public ResultMsg getWorkStatisticsPage(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "rwdbh", required = false, defaultValue = "-1")  String rwdbh,
                                     @RequestParam(name = "startTime", required = false, defaultValue = "")  String startTime,
                                     @RequestParam(name = "endTime", required = false, defaultValue = "")  String endTime,
                                     @RequestParam(defaultValue = "-1") Long wtfId,
                                     @RequestParam(defaultValue = "-1") Long wtfchId,
                                     @RequestParam(defaultValue = "0")Long jyyId
    ) {
        ResultMsg resultMsg = workService.getWorkStatisticsPage(request,page,size,rwdbh,startTime,endTime,wtfId,wtfchId,jyyId);
        return resultMsg;
    }



    /**
     * 工作量 统计的分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getWorkStatistics2")
    public ResultMsg getWorkStatistics2(HttpServletRequest request,
                                           @RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size,
                                           @RequestParam(name = "rwdbh", required = false, defaultValue = "-1")  String rwdbh,
                                           @RequestParam(name = "startTime", required = false, defaultValue = "")  String startTime,
                                           @RequestParam(name = "endTime", required = false, defaultValue = "")  String endTime,
                                           @RequestParam(defaultValue = "-1") Long wtfId,
                                           @RequestParam(defaultValue = "-1") Long wtfchId,
                                           @RequestParam(defaultValue = "0")Long jyyId
    ) {
        ResultMsg resultMsg = workService.getWorkStatistics2(request,page,size,rwdbh,startTime,endTime,wtfId,wtfchId,jyyId);
        return resultMsg;
    }





    /**
     * 台账统计的分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getTzStatisticsPage")
    public ResultMsg getTzStatisticsPage(HttpServletRequest request,
                                           @RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size,
                                           @RequestParam(name = "rwdbh", required = false, defaultValue = "")  String rwdbh,
                                           @RequestParam(name = "startTime", required = false, defaultValue = "")  String startTime,
                                           @RequestParam(name = "endTime", required = false, defaultValue = "")  String endTime,
                                           @RequestParam(defaultValue = "-1") Long wtfId,
                                         @RequestParam(defaultValue = "0") Long wtfchId
    ) {
        ResultMsg resultMsg = workService.getTzStatisticsPage(request,page,size,rwdbh,startTime,endTime,wtfId,wtfchId);
        return resultMsg;
    }




    /**
     * 分页查询任务
     *
     * @param request
     * @return
     */
    @RequestMapping("/api/getWorkListPageAll")
    public ResultMsg getWorkListPageAll(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "rwdbh", required = false, defaultValue = "")  String rwdbh,
                                     @RequestParam(defaultValue = "0")Integer wtfId,
                                     @RequestParam(defaultValue = "0")Integer wtfchId,
                                     @RequestParam(defaultValue = "0")Integer mtype,
                                     @RequestParam(defaultValue = "0")Integer workTYpe,
                                     @RequestParam(defaultValue = "0")Long jyyId

                                        ) {
        ResultMsg resultMsg = workService.getWorkListPageAll(request,page,size,rwdbh,wtfId,wtfchId,mtype,workTYpe,jyyId);
        return resultMsg;
    }



    /**
     * 检验任务单
     * @param request
     * @param rwdbh  任务单编号
     * @return
     */
    @RequestMapping("/api/getJyrwdData")
    public  ResultMsg getJyrwdData(HttpServletRequest request,String rwdbh){
        ResultMsg resultMsg = workService.getJyrwdData(request,rwdbh);
        return resultMsg;
    }



    /**
     * 修改检验员
     * @return
     */
    @RequestMapping(value = "/api/updateJyyById")
    public ResultMsg updateJyyById(HttpServletRequest request,long workId,String jyy,long jyyId){
        ResultMsg resultMsg = workService.updateJyyById(request,workId,jyy,jyyId);
        return resultMsg;
    }


}
